package com.cskaoyan.market.admin.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cskaoyan.market.db.domain.MarketComment;
import com.cskaoyan.market.db.domain.MarketCommentExample;
import com.cskaoyan.market.db.mapper.MarketCommentMapper;
import com.cskaoyan.market.admin.service.MarketAdminCommentService;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.MyBatisUtil;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
    *@Author：檀志浩
    *@Package：com.cskaoyan.market.service.impl
    *@Project：Project1
    *@name：MarketAdminCommentServiceImpl
    *@Date：2023/5/10  10:59
    *@Filename：MarketAdminCommentServiceImpl
    */
@Service
public class MarketAdminCommentServiceImpl implements MarketAdminCommentService {
    @Autowired
    private MarketCommentMapper marketCommentMapper;

    @Override
    public int deleteComment(String requestBody) {
        String id = JacksonUtil.parseString(requestBody, "id");
        
        
        MarketComment marketComment = marketCommentMapper.selectByPrimaryKey(Integer.parseInt(id));
        marketComment.setDeleted(true);
        int i = marketCommentMapper.updateByPrimaryKey(marketComment);
        
        
        if (i == 1) {
            return 200;
        } else {
            return 404;
        }

    }

    @Override
    public List<MarketComment> getCommentList(String page, String limit, String sort, String order) {
        int intPage = Integer.parseInt(page);
        int intlimit = Integer.parseInt(limit);

        
        MarketCommentExample marketCommentExample = new MarketCommentExample();
        MarketCommentExample.Criteria criteria = marketCommentExample.createCriteria();
        marketCommentExample.orderBy(sort + " " + order);
        criteria.andDeletedEqualTo(false);

        PageHelper.startPage(intPage, intlimit);
        List<MarketComment> marketComments = marketCommentMapper.selectByExample(marketCommentExample);
        
        
        return marketComments;
    }
}
